package com.trace.pplos.parse.dao.dataobject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class HjrkInfoWithBLOBs extends HjrkInfo {
    private static final Logger logger = LoggerFactory.getLogger(HjrkInfoWithBLOBs.class);
    private String hzsjzh;

    private String hzyhkzh;

    public HjrkInfoWithBLOBs(Integer id, Integer fwlx, String xm, Integer xb, String gmsfhm, Date csrq, String dhhm, String imei, String mac, String meid, String qqzh, String tbzh, String jdzh, String wbzh, String wxzh, String hjdz, String xjdz, String mz, String rylx, String address, String lng, String lat, String hzsfImgPath, String hztzImgPath, String hzxcImgPath, String hzfpImgPath, String bzrdhhm, String bzrxm, String fddh, String fdxm, String cjdw, Date gmtCreate, String gmtCreateUser, Date gmtModified, String gmtModifiedUser, Integer status, String hzsjzh, String hzyhkzh) {
        super(id, fwlx, xm, xb, gmsfhm, csrq, dhhm, imei, mac, meid, qqzh, tbzh, jdzh, wbzh, wxzh, hjdz, xjdz, mz, rylx, address, lng, lat, hzsfImgPath, hztzImgPath, hzxcImgPath, hzfpImgPath, bzrdhhm, bzrxm, fddh, fdxm, cjdw, gmtCreate, gmtCreateUser, gmtModified, gmtModifiedUser, status);
        this.hzsjzh = hzsjzh;
        this.hzyhkzh = hzyhkzh;
    }

    public HjrkInfoWithBLOBs() {
        super();
    }

    public String getHzsjzh() {
        return hzsjzh;
    }

    public void setHzsjzh(String hzsjzh) {
        this.hzsjzh = hzsjzh == null ? null : hzsjzh.trim();
    }

    public String getHzyhkzh() {
        return hzyhkzh;
    }

    public void setHzyhkzh(String hzyhkzh) {
        this.hzyhkzh = hzyhkzh == null ? null : hzyhkzh.trim();
    }

    public static HjrkInfoWithBLOBs toBean(String result){
        try {
            HjrkInfoWithBLOBs info = new HjrkInfoWithBLOBs();
            JSONObject record = JSON.parseObject(result);
            //主表信息
            info.setFwlx(record.getInteger("fwlx"));
            info.setXm(record.getString("mc"));
            info.setXb(record.getInteger("xb"));
            info.setGmsfhm(record.getString("sfhm"));
            info.setCsrq(record.getDate("csrq"));
            info.setDhhm(record.getString("dhhm"));
            info.setImei(record.getString("imei"));
            info.setMac(record.getString("mac"));
            info.setMeid(record.getString("meid"));
            info.setQqzh(record.getString("qqzh"));
            info.setTbzh(record.getString("taobao"));
            info.setJdzh(record.getString("jingdong"));
            info.setWbzh(record.getString("weibo"));
            info.setWxzh(record.getString("weixin"));
            info.setHjdz(record.getString("hjdz"));
            info.setXjdz(record.getString("xjdz"));
            info.setMz(record.getString("ssmz"));
            info.setRylx(record.getString("rylx"));
            info.setAddress(record.getString("address"));
            info.setLng(record.getString("longitude"));
            info.setLat(record.getString("latitude"));
            //身份证照片
            String hzsfImgPath = "";
            JSONArray hzsfImgPathlist = record.getJSONArray("sfzzPictureList");
            for (int i = 0; i < hzsfImgPathlist.size(); i++) {
                JSONObject dataObj = hzsfImgPathlist.getJSONObject(i);
                hzsfImgPath += dataObj.getString("path") + ",";
            }
            info.setHzsfImgPath(hzsfImgPath);

            //特征照片
            String hztzImgPath = "";
            JSONArray hztzImgPathlist = record.getJSONArray("tzzpPictureList");
            for (int i = 0; i < hztzImgPathlist.size(); i++) {
                JSONObject dataObj = hztzImgPathlist.getJSONObject(i);
                hztzImgPath += dataObj.getString("path") + ",";
            }
            info.setHztzImgPath(hztzImgPath);

            //现场照片
            String hzxcImgPath = "";
            JSONArray hzxcImgPathlist = record.getJSONArray("xcpsPictureList");
            for (int i = 0; i < hzxcImgPathlist.size(); i++) {
                JSONObject dataObj = hzxcImgPathlist.getJSONObject(i);
                hzxcImgPath += dataObj.getString("path") + ",";
            }
            info.setHzxcImgPath(hzxcImgPath);

            //翻拍照片
            String hzfpImgPath = "";
            JSONArray hzfpImgPathlist = record.getJSONArray("xcpsPictureList");
            for (int i = 0; i < hzfpImgPathlist.size(); i++) {
                JSONObject dataObj = hzfpImgPathlist.getJSONObject(i);
                hzfpImgPath += dataObj.getString("path") + ",";
            }
            info.setHzfpImgPath(hzfpImgPath);

            info.setBzrdhhm(record.getString("bzrdhhm"));
            info.setBzrxm(record.getString("bzrxm"));
            info.setFddh(record.getString("fddh"));
            info.setFdxm(record.getString("fdxm"));
            info.setCjdw(record.getString("cjdw"));
            info.setGmtCreate(record.getDate("createdAt"));
            info.setGmtCreateUser(record.getString("createdBy"));
            info.setGmtModified(new Date());
            info.setStatus(1);   //默认状态为可用
            info.setGmtModifiedUser(record.getString("modifiedBy"));
            //社交账号
            String hzsjzh = "";
            JSONArray hzsjzhlist = record.getJSONArray("sjzhList");
            for (int i = 0; i < hzsjzhlist.size(); i++) {
                JSONObject dataObj = hzsjzhlist.getJSONObject(i);
                hzsjzh += dataObj.getString("content") + ",";
            }
            info.setHzsjzh(hzsjzh);
            //银行账号
            String hzyhkzh = "";
            JSONArray hzyhkzhlist = record.getJSONArray("yhzhList");
            for (int i = 0; i < hzyhkzhlist.size(); i++) {
                JSONObject dataObj = hzyhkzhlist.getJSONObject(i);
                hzyhkzh += dataObj.getString("content") + ",";
            }
            info.setHzyhkzh(hzyhkzh);

            //子表信息
            List<HjrkDetailInfoWithBLOBs> detailList = new ArrayList();
            JSONArray thrList = record.getJSONArray("thrList");
            for (int i = 0; i < thrList.size(); i++) {
                JSONObject dataObj = thrList.getJSONObject(i);
                HjrkDetailInfoWithBLOBs hdinfo = new HjrkDetailInfoWithBLOBs();
                hdinfo.setYhzgx(dataObj.getInteger("yhzgx"));
                hdinfo.setFwlx(info.getFwlx());
                hdinfo.setXm(dataObj.getString("mc"));
                hdinfo.setXb(dataObj.getInteger("xb"));
                hdinfo.setGmsfhm(dataObj.getString("sfhm"));
                hdinfo.setCsrq(dataObj.getDate("csrq"));
                hdinfo.setDhhm(dataObj.getString("dhhm"));
                hdinfo.setImei(dataObj.getString("imei"));
                hdinfo.setMac(dataObj.getString("mac"));
                hdinfo.setMeid(dataObj.getString("meid"));
                hdinfo.setQqzh(dataObj.getString("qq"));
                hdinfo.setTbzh(dataObj.getString("taobao"));
                hdinfo.setJdzh(dataObj.getString("jingdong"));
                hdinfo.setWbzh(dataObj.getString("weibo"));
                hdinfo.setWxzh(dataObj.getString("weixin"));
                hdinfo.setHjdz(dataObj.getString("hjdz"));
                hdinfo.setXjdz(dataObj.getString("xjdz"));
                hdinfo.setMz(dataObj.getString("ssmz"));
                hdinfo.setRylx(dataObj.getString("rylx"));
                hdinfo.setAddress(info.getAddress());
                hdinfo.setLng(info.getLng());
                hdinfo.setLat(info.getLat());
                //身份证照片
                String dhzsfImgPath = "";
                JSONArray dhzsfImgPathlist = record.getJSONArray("sfzzPictureList");
                for (int j = 0; j < dhzsfImgPathlist.size(); j++) {
                    JSONObject ddataObj = dhzsfImgPathlist.getJSONObject(j);
                    dhzsfImgPath += ddataObj.getString("path") + ",";
                }
                hdinfo.setHzsfImgPath(dhzsfImgPath);
                //特征照片
                String dhztzImgPath = "";
                JSONArray dhztzImgPathlist = record.getJSONArray("tzzpPictureList");
                for (int j = 0; j < dhztzImgPathlist.size(); j++) {
                    JSONObject ddataObj = dhztzImgPathlist.getJSONObject(j);
                    dhzsfImgPath += ddataObj.getString("path") + ",";
                }
                hdinfo.setHztzImgPath(dhztzImgPath);
                //现场照片
                String dhzxcImgPath = "";
                JSONArray dhzxcImgPathlist = record.getJSONArray("xcpsPictureList");
                for (int j = 0; j < dhzxcImgPathlist.size(); j++) {
                    JSONObject ddataObj = dhzxcImgPathlist.getJSONObject(j);
                    dhzxcImgPath += ddataObj.getString("path") + ",";
                }
                hdinfo.setHzxcImgPath(dhzxcImgPath);
                //翻拍照片
                String dhzfpImgPath = "";
                JSONArray dhzfpImgPathlist = record.getJSONArray("zpfpPictureList");
                for (int j = 0; j < dhzfpImgPathlist.size(); j++) {
                    JSONObject ddataObj = dhzfpImgPathlist.getJSONObject(j);
                    dhzfpImgPath += ddataObj.getString("path") + ",";
                }
                hdinfo.setHzfpImgPath(dhzfpImgPath);

                hdinfo.setGmtCreate(info.getGmtCreate());
                hdinfo.setGmtCreateUser(info.getGmtCreateUser());
                hdinfo.setGmtModified(new Date());
                hdinfo.setGmtModifiedUser(info.getGmtModifiedUser());
                detailList.add(hdinfo);
            }
            info.setDetailInfoList(detailList);
            return info;
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    public static void main(String[] args) {
        try {
            String url = "F:\\字段描述档 - 副本.txt";
            File file = new File(url);
            InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");//考虑到编码格式
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;
            String recode = "";
            while ((lineTxt = bufferedReader.readLine()) != null) {
                recode += lineTxt;
            }
            toBean(recode);
            read.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}